<template>
  <div id="testListEdit">
    <!-- Form-开始 -->
    <el-dialog :title="`编辑标本号`" width="500px" v-model="dialogFormVisible" draggable destroy-on-close>
      <el-form ref="pagepanelnameForm" :model="mainInfo" label-width="80px" class="form-input-m baseForm">
        <el-form-item prop="sampleNo" label="标本号">
          <el-input v-model="mainInfo.sampleNo" name="sampleNo" clearable style="width:100%" />
        </el-form-item>
        <el-form-item>
          <span class="text-bold text-orange">{{`修改前标本号：${beforeEdit}`}}</span>
        </el-form-item>
        <el-form-item v-if="isEditSuccess">
          <span class="text-bold text-green margin-right-xs">
            <vxe-icon name="vxe-icon-success-circle-fill" roll></vxe-icon>
          </span>
          <span class="text-bold text-green">{{`修改成功`}}</span>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <vxe-button type="text" :disabled="showLoading" class="button-white padding-lr-xs" @click="closeDialog()" content="取消"></vxe-button>
          <vxe-button :loading="showLoading" :disabled="showLoading" type="text" class="button-blue padding-lr-xs" @click="confirm()" content="确认"> </vxe-button>
        </div>
      </template>
    </el-dialog>
    <!-- Form-结束 -->
  </div>
</template>
<script setup lang="ts">
import { ref, reactive, getCurrentInstance, watch, onMounted } from 'vue';
import { pageSizes, DateToString, formatDateTime, IsEmpty } from '@/utils/common';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import { VXETable } from 'vxe-table';
import XEUtils from 'xe-utils';
// import func from 'vue-temp/vue-editor-bridge';

// 全局变量定义区 ==========
let { proxy }: any = getCurrentInstance();
let showLoading = ref(false);
let dialogFormVisible = ref(false);
let isEditSuccess = ref(null);
let props = defineProps({}) as any;

let mainInfo: any = reactive({});
let beforeEdit = ref('');

defineExpose({

  initPage
})
onMounted(() => {
  //Todo
});
// 接收父组件传过来的弹框展开状态
function initPage(row) {
  isEditSuccess.value = false;
  if (IsEmpty(row.id) || IsEmpty(row.sampleNo)) {
    VxeMessage('请选择一条记录修改', VxeNotifyType.error);
    return;
  }
  beforeEdit.value = row.sampleNo;
  Object.assign(mainInfo, row);
  dialogFormVisible.value = true;
}
// 取消操作
function closeDialog() {
  dialogFormVisible.value = false;
}
/**确认修改标本号 */
function confirm() {
  isEditSuccess.value = false;
  showLoading.value = true;
  let data = {
    rptGroup: mainInfo.rptGroup,
    sampleNo: mainInfo.sampleNo,
    sampleda: mainInfo.sampleda,
    labMaininfo: mainInfo
  };
  proxy.$http
    .post('/lab/maininfo/updateMaininfo', data)
    .then((res: any) => {
      if (res && res.status && res.status.code !== 1) {
        VxeMessage(res.status.msg, VxeNotifyType.error);
      } else if (res && res.status && res.status.code === 1) {
        isEditSuccess.value = true;
        proxy.$emit('uptSuccess', res.data);
      } else {
        VxeMessage('请求错误', VxeNotifyType.error);
      }
      showLoading.value = false;
      setTimeout(() => {
        closeDialog();
      }, 1000);
    })
    .catch((err: any) => {
      showLoading.value = false;
      VxeMessage('修改标本号失败,请联系管理员', VxeNotifyType.error);
    });
}
</script>
<style lang="scss" scope>
#testListEdit {
  height: 100%;
}
</style>
